<link href="Style.css" rel="stylesheet" type="text/css" />
<?php
session_start(); 

require("sql_functions.php");

if(isset($_SESSION['user']))
{
	$user = $_SESSION['user'];
	$employee = sql_getEmployee($user);
	$firstName = $employee['FirstName'];
	$lastName = $employee['LastName'];

	$projects = sql_getUserProjects($user);

	echo "<html>"; 
	echo "<head>"; 
	echo "</head>"; 
	echo "<body>";
	echo "<p>Dashboard for $firstName $lastName"; 
	echo "<p>My Projects";			
	echo "<table border='1'>";	
	echo "<tr><td>ID</td><td>Project Title</td><td>My Role</td>";
	while($row = mysql_fetch_array($projects))
	{		
		$pid = $row['ID'];
		$pTitle = $row['Title'];
		$pMgrEmail = $row['ManagerEmail'];

		echo "<tr><td>";
		echo "$pid";
		echo "</td><td>";
		if(!strcmp($pMgrEmail,$user))
		{
			$pRole = "Project Manager";
			echo "<a href=\"project_info.php?projectID=$pid\">$pTitle</a>";
		}
		else
		{
			$pRole = "Team Member";
			echo "$pTitle";
		}
		echo "</td><td>";
		echo "$pRole";
		echo "</td></tr>";
	}
	echo "</table>";

	$tasks = sql_getUserTasks($user);

	echo "<p><p>My Tasks";			
	echo "<table border='1'>";	
	echo "<tr><td>Task Name</td><td>Project Title</td><td>Due Date</td>";
	while($row = mysql_fetch_array($tasks))
	{		
		$tIsClosed = $row['IsClosed'];

		if(!$tIsClosed)
		{
			$tName = $row['TaskName'];
			$tDueDate = $row['DueDate'];

			$pid = $row['ProjectID'];
			$project = sql_getProject($pid);
			$pName = $project['Title'];
      $mName = $row['MilestoneName'];

			echo "<tr><td>";
			echo "<a href=\"time_tracking.php?projectID=$pid&MilestoneName=$mName&taskName=$tName\">$tName</a>";
			echo "</td><td>";
			echo "$pName";
			echo "</td><td>";
			echo "$tDueDate";
			echo "</td></tr>";
		}
	}
	echo "</table>";
			

	echo "<form action=\"project_info.php\" method=\"POST\">"; 
	echo "<p><input type=\"submit\" name=\"save\" value=\"New Project\" />"; 
	echo "</form>"; 
  
	echo "<p><a href=\"index.php\">Log Out</a>";
	echo "<p><a href=\"project_tasks_report.php\">Project Tasks Report</a>";
	echo "<p><a href=\"employee_tasks_report.php\">Employee Tasks Report</a>";
  
	echo "</body>"; 
	echo "</html>"; 			
				
}
else
{
	echo "Must be logged in to view this page.";
}

?>
